#include <stdio.h>
#include <conio.h>
#include <bios.h>
#include <dos.h>

#ifdef __cplusplus
	#define __CPPARGS ...
#else
	#define __CPPARGS
#endif

#define INTR 0x71


void init_mouse()
{
	asm mov ax,0
	asm int 0x33
	asm mov ax,1
	asm int 0x33
}

void get_mouse(int *x,int *y)
{
	int xx,yy;
	asm mov ax,3
	asm int 0x33
	asm mov xx,cx
	asm mov yy,dx
	*x = xx;
	*y = yy;
}

void mouse_wait()
{
	int timeout = 10000;
	while(timeout--) {
		if(inportb(0x64) & 1)
			break;
	}
}

unsigned char get_byte()
{
	mouse_wait();
	return inportb(0x60);
}

void interrupt ( *oldhandler)(__CPPARGS);

volatile int count=0,b1,b2,b3,b4,b5,b6;

void interrupt handler(__CPPARGS)
{
	count++;
	b1 = get_byte();
	b2 = get_byte();
	b3 = get_byte();
	oldhandler();
}

int main(void)
{
	init_mouse();
	oldhandler = getvect(INTR);
	setvect(INTR, handler);

	while(!bioskey(1)) {
		printf("\ncount = %d %d %d %d %d %d %d",count,b1,b2,b3,b4,b5,b6);
	}

	setvect(INTR, oldhandler);

	return 0;
}
